
"use strict";

angular.module('app.user').controller('ModifyInfoCtrl', function ($scope, $rootScope,$cookieStore,$http) {
   $scope.data = {};
    var userid = $cookieStore.get("userid");
    $scope.modifyinfo = function () {
        // console.log($scope.data);
        if($scope.data.oldpasswd == null || $scope.data.oldpasswd == ''){
            new Notify('info','请输入旧密码'); 
            return;
        }
        if($scope.data.newpasswd1 == null || $scope.data.newpasswd1 == ''){
            new Notify('info','请输入新密码'); 
            return;
        }
        if($scope.data.newpasswd1 != $scope.data.newpasswd2){
            new Notify('info','两次新密码输入不一致'); 
            return;
        }
        //当旧密码正确 并且两次输入的新密码相同时
        //修改密码
        $http.put(baseurl+"/modifypass?id=="+userid,{pass: $scope.data.newpasswd2,oldpass:$scope.data.oldpasswd}).then(function(res){
            // console.log(res.data);
            if(res.data.ret == 1){
                // alert('修改成功')
                new Notify('success','修改成功');
                window.location.href =  "#/perUser";
            }else{
                // new Notify('fail','密码修改失败');
                alert(res.data.info);
            }
        }) 
    }




});